# -*- coding: utf-8 -*-
import datetime, time
from re import match
month_rus = [ [], ['Январь','января'], ['Февраль','февраля'], ['Март','марта'],['Апрель','апреля'],['Май','мая'],['Июнь','июня'],['Июль','июля'],['Август','августа'],['Сентябрь','сентября'],['Октябрь','октября'],['Ноябрь','ноября'],['Декабрь','декабря']]


def date_format(date):        
    
    #Trancivieng Object
    t = str(date).replace(':',"-").replace(' ','-').replace('.','-').split('-')               
    year = t[0]; month=t[1]; day = t[2]; hour = t[3]; minute = t[4];
    
    string_date = str( datetime.datetime.today() )
    
    m_date = match("^(\d{1,4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})",string_date)        
    c_year = m_date.group(1); c_month=m_date.group(2); c_day = m_date.group(3); c_hour = m_date.group(4); c_minute = m_date.group(5);
    
    status = ''
    timing = hour + ':' + minute      
    if c_year == year and month == c_month and day == c_day and hour == c_hour and int(c_minute) - int(minute) <= 1:
        status = 'Только что, %s' % timing
    elif c_year == year and month == c_month and day == c_day and hour == c_hour and int(c_minute) - int(minute) <= 10:         
        
        difference = int(c_minute) - int(minute)           
        #if not status:                
        status = '%d минут%s назад, %s' % ( difference, 'ы' if difference < 5 else '', timing )
            
    #elif c_year == year and month == c_month and day == c_day and hour == c_hour or int(c_hour) - int(hour) == 1 and int(c_minute) - int(minute) <= 10: 
            
    elif c_year == year and month == c_month and day == c_day:
        
        status = 'Сегодня, %s' % timing
    elif c_year == year and month == c_month and int(c_day) - int(day)==1:            
        status = 'Вчера, %s' % timing
    else:            
        status = '%s %s %s, %s:%s' %( day[1] if int(day)<=9 else day, month_rus[int(month)][1],year, hour, minute)
    return status


def simple_date_format(date):
    currentDate = datetime.datetime.now()
    
    daysDiffer = (currentDate - date).days
    
    form = '%d %s' %  (date.day, month_rus[date.month][1] )
    if not daysDiffer:
        timeText = 'Сегодня, %s' % form
    if daysDiffer == 1:
        timeText = 'Вчера, %s' % form 
    if daysDiffer > 1:
        timeText = form
        
        
    return timeText